//
//  UserTennisLineController.m
//  CoolTennisBall
//
//  Created by Coollang on 16/8/29.
//  Copyright © 2016年 CoolLang. All rights reserved.
//

#import "UserTennisLineController.h"
#import "UserArrowItem.h"
#import "UserSaveItem.h"
#import "UserLabelItem.h"
#import "UserGroup.h"
#import "UserSericesChildVC.h"


@interface UserTennisLineController ()

@end

@implementation UserTennisLineController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self loadTableViewDataSource];
}

- (void)loadTableViewDataSource {
    
    NSArray *brandAndModelArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"TennisLineBrandAndModel.plist" ofType:nil]];
    UserGroup *group0 = [[UserGroup alloc] init];
    
    group0.headHeight = kAutoHei(24);
    
    UserLabelItem *item0_0 = [UserLabelItem itemWithTitle:NSLocalizedString(@"User.Generic", nil)];
    [group0.items addObject:item0_0];
    
    __weak typeof(self) weakSelf = self;
    
    [brandAndModelArray enumerateObjectsUsingBlock:^(NSDictionary *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        UserArrowItem *arrowItem = [UserArrowItem itemWithTitle:obj[@"TennisLineBrand"]];
        __weak typeof(arrowItem) weakArrowSelf = arrowItem;
        [arrowItem setBlock:^{
            UserSericesChildVC *childVc = [[UserSericesChildVC alloc] init];
            childVc.childType = SericesChildTennisLineBrandAndModle;
            childVc.content = weakArrowSelf.title;
            [childVc.groups addObject:[weakSelf racketModelArray:obj[@"TennisLineModel"]]];
            
            [weakSelf.navigationController pushViewController:childVc animated:YES];
        }];
        
        [group0.items addObject:arrowItem];
        
    }];
    
    [self.groups addObject:group0];
}

- (UserGroup *)racketModelArray:(NSArray *)stringArr {
    
    UserGroup *group0 = [[UserGroup alloc] init];
    
    group0.headHeight = kAutoHei(24);
    
    [stringArr enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UserSaveItem *saveItem = [UserSaveItem itemWithTitle:obj];
        [group0.items addObject:saveItem];
    }];
    
    return group0;
}


@end
